.\" -*- nroff -*-
.\" Copyright 2010 Cisco Systems, Inc.  All rights reserved.
.\" Copyright 2006-2008 Sun Microsystems, Inc.
.\" Copyright (c) 1996 Thinking Machines
.\" Copyright (c) 2020      Google, LLC. All rights reserved.
.\" $COPYRIGHT$
.TH MPI_Type_create_keyval 3 "#OMPI_DATE#" "#PACKAGE_VERSION#" "#PACKAGE_NAME#"
.SH NAME
\fBMPI_Type_create_keyval\fP \- Generates a new attribute key for caching on data types.

.SH SYNTAX
.ft R
.SH C Syntax
.nf
#include <mpi.h>
int MPI_Type_create_keyval(MPI_Type_copy_attr_function *\fItype_copy_attr_fn\fP,
	MPI_Type_delete_attr_function *\fItype_delete_attr_fn\fP,
	int *\fItype_keyval\fP, void *\fIextra_state\fP)

.fi
.SH Fortran Syntax (see FORTRAN 77 NOTES)
.nf
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_TYPE_CREATE_KEYVAL(\fITYPE_COPY_ATTR_FN, TYPE_DELETE_ATTR_FN,
		TYPE_KEYVAL, EXTRA_STATE, IERROR\fP)
	EXTERNAL \fITYPE_COPY_ATTR_FN, TYPE_DELETE_ATTR_FN\fP
	INTEGER	\fITYPE_KEYVAL, IERROR \fP
	INTEGER(KIND=MPI_ADDRESS_KIND) \fIEXTRA_STATE\fP

.fi
.SH Fortran 2008 Syntax
.nf
USE mpi_f08
MPI_Type_create_keyval(\fItype_copy_attr_fn\fP, \fItype_delete_attr_fn\fP, \fItype_keyval\fP,
		\fIextra_state\fP, \fIierror\fP)
	PROCEDURE(MPI_Type_copy_attr_function) :: \fItype_copy_attr_fn\fP
	PROCEDURE(MPI_Type_delete_attr_function) :: \fItype_delete_attr_fn\fP
	INTEGER, INTENT(OUT) :: \fItype_keyval\fP
	INTEGER(KIND=MPI_ADDRESS_KIND), INTENT(IN) :: \fIextra_state\fP
	INTEGER, OPTIONAL, INTENT(OUT) :: \fIierror\fP

.fi
.SH INPUT PARAMETERS
.ft R
.TP 1i
type_copy_attr_fn
Copy callback function for \fItype_keyval\fP (function).
.TP 1i
type_delete_attr_fn
Delete callback function for \fItype_keyval\fP (function).
.TP 1i
extra_state
Extra state for callback functions.

.SH OUTPUT PARAMETERS
.ft R
.TP 1i
type_keyval
Key value for future access (integer).
.TP 1i
IERROR
Fortran only: Error status (integer).

.SH DESCRIPTION
.ft R
MPI_Type_create_keyval generates a new attribute key for caching on data types. This routine partially replaces MPI_Keyval_create.
.sp
The argument \fItype_copy_attr_fn\fP may be specified as MPI_TYPE_NULL_COPY_FN or MPI_TYPE_DUP_FN from C or Fortran. MPI_TYPE_NULL_COPY_FN is a function that does nothing other than returning \fIflag\fP = 0 and MPI_SUCCESS. MPI_TYPE_DUP_FN is a simple-minded copy function that sets \fIflag\fP = 1, returns the value of \fIattribute_val_in\fP in \fIattribute_val_out\fP, and returns MPI_SUCCESS.
.sp
The argument \fItype_delete_attr_fn\fP may be specified as MPI_TYPE_NULL_DELETE_FN from C or Fortran. MPI_TYPE_NULL_DELETE_FN is a function that does nothing beyond returning MPI_SUCCESS.
The C callback functions are:
.sp
.nf
typedef int MPI_Type_copy_attr_function(MPI_Datatype \fIoldtype\fP,
            int \fItype_keyval\fP, void *\fIextra_state\fP, void *\fIattribute_val_in\fP,
            void *\fIattribute_val_out\fP, int *\fIflag\fP);
.fi
and
.nf
typedef int MPI_Type_delete_attr_function(MPI_Datatype \fItype\fP, int \fItype_keyval\fP,
             void *\fIattribute_val\fP, void *\fIextra_state\fP);
.fi
.sp
The Fortran callback functions are:
.sp
.nf
SUBROUTINE TYPE_COPY_ATTR_FN(\fIOLDTYPE, TYPE_KEYVAL, EXTRA_STATE,
             ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT, FLAG, IERROR\fP)
    INTEGER \fIOLDTYPE, TYPE KEYVAL, IERROR\fP
    INTEGER(KIND=MPI_ADDRESS_KIND) \fIEXTRA_STATE,
        ATTRIBUTE_VAL_IN, ATTRIBUTE_VAL_OUT\fP
    LOGICAL \fIFLAG\fP
.fi
and
.nf
SUBROUTINE TYPE_DELETE_ATTR_FN(\fITYPE, TYPE_KEYVAL, ATTRIBUTE_VAL, EXTRA_STATE,
             IERROR\fP)
    INTEGER \fITYPE, TYPE_KEYVAL, IERROR\fP
    INTEGER(KIND=MPI_ADDRESS_KIND) \fIATTRIBUTE VAL, EXTRA_STATE\fP
.fi
.sp

.SH FORTRAN 77 NOTES
.ft R
The MPI standard prescribes portable Fortran syntax for
the \fIEXTRA_STATE\fP argument only for Fortran 90.  FORTRAN 77
users may use the non-portable syntax
.sp
.nf
     INTEGER*MPI_ADDRESS_KIND \fIEXTRA_STATE\fP
.fi
.sp
where MPI_ADDRESS_KIND is a constant defined in mpif.h
and gives the length of the declared integer in bytes.

.SH ERRORS
Almost all MPI routines return an error value; C routines as the value of the function and Fortran routines in the last argument.
.sp
Before the error value is returned, the current MPI error handler is
called. By default, this error handler aborts the MPI job, except for I/O function errors. The error handler may be changed with MPI_Comm_set_errhandler; the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error.

.SH SEE ALSO
.ft R
.sp
MPI_Type_free_keyval

